<template>
	<view>
		<uni-notice-bar v-show='false' text="密码暂时不支持修改，待后续版本上线此功能"></uni-notice-bar>
		<!-- 卡ID -->
		<u-row customStyle="margin-bottom: 10px;margin-top: 20px">
			<u-col span="1"></u-col>
			<u-col span="10">
				<view class="cardno">
					<text>卡ID:</text><text>{{cardno}}</text>
				</view>
			</u-col>
			<u-col span="1"></u-col>
		</u-row>
		<!-- 输入旧密码 -->
		<u-row customStyle="margin-bottom: 10px">
			<u-col span="1"></u-col>
			<u-col span="10">
				<u--input
				    placeholder="请输旧密码"
				    border="surround"
					type="number"
				    v-model="oldPwd"
				  ></u--input>
			</u-col>
			<u-col span="1"></u-col>
		</u-row>
		<!-- 卡新密码 -->
		<u-row customStyle="margin-bottom: 10px">
			<u-col span="1"></u-col>
			<u-col span="10">
				<u--input
				    placeholder="请输新密码"
				    border="surround"
					type="number"
				    v-model="newPwd"
				  ></u--input>
			</u-col>
			<u-col span="1"></u-col>
		</u-row>
		<!-- 校园卡密码 -->
		<u-row customStyle="margin-bottom: 10px">
			<u-col span="1"></u-col>
			<u-col span="10">
				<u--input
				    placeholder="再次输入新密码"
				    border="surround"
				    type="text"
				    v-model="newPwd2"
				  ></u--input>
			</u-col>
			<u-col span="1"></u-col>
		</u-row>
		<!-- 按钮 -->
		<u-row customStyle="margin-bottom: 10px">
			<u-col span="1"></u-col>
			<u-col span="10">
				<u-button :disabled="isButton" type="primary" text="提交" @click="submit"></u-button>
			</u-col>
			<u-col span="1"></u-col>
		</u-row>
		<!-- 重度提示 -->
		<u-row customStyle="margin-bottom: 10px" v-show="true">
			<u-col span="1"></u-col>
			<u-col span="10">
				<u-alert title="新密码需要大于6位" type = "error"></u-alert>
			</u-col>
			<u-col span="1"></u-col>
		</u-row>
	</view>
</template>

<script>
	import {mixin} from '../../../mixin.js'
	export default {
		data() {
			return {
				oldPwd:'',
				newPwd:'',
				newPwd2:'',
			};
		},
		mixins:[mixin],
		watch:{
			
		},
		computed:{
			cardno(){
				return uni.getStorageSync('cardno')
			},
			isButton(){
				if(this.oldPwd=='' || this.newPwd == '' || this.newPwd2 ==''){
					return true
				}else{
					return false
				}
			}
		},
		methods:{
			submit(){
				if(this.newPwd != this.newPwd2){
					uni.showModal({
						content:'两次新密码不一致',
						showCancel:false,
					})
					return 0
				}else if(this.newPwd.length < 6 || this.newPwd2.length < 6){
					uni.showModal({
						content:'新密码长度小于6',
						showCancel:false,
					})
					return 0
				}
				uni.showModal({
					title:'确认修改密码?',
					success:res=>{
						if(res.confirm){
							uni.showLoading({
								title:"正在提交数据...",
								mask:true
							});
							const params = {
								cardno:this.cardno,
								clienttype:'Android',
								iplanetdirectorypro:uni.getStorageSync('msg'),
								newpwd:this.getDes(this.newPwd),
								oldPwd:this.getDes(this.oldPwd),
								schoolcode:'ccufe'
							}
							uni.request({
								url:"http://ykt.ccufe.com:8070/Api/Card/ChangeQueryPwdPlus",
								method:'POST',
								header:{
									'Cache-Control':'no-cache',
									'Accept':'*/*',
									'Accept-Encoding':'gzip',
									'Connection':'keep-alive',
									'Content-Type':'application/x-www-form-urlencoded',
									'Content-Length':'154'
								},
								data:{
									cardno:this.cardno,
									clienttype:'Android',
									iplanetdirectorypro:uni.getStorageSync('msg'),
									newpwd:this.getDes(this.newPwd),
									oldPwd:this.getDes(this.oldPwd),
									schoolcode:'ccufe',
									sign:this.getMd5(this.getObjToStr(params))
								},
								success:res=>{
									
									if(res.data.success==true || res.data.success=='true'){
										console.log(res)
									}
								},
								complete:e=> {
									uni.hideLoading();
									if(e.data.msg == 'NL'){
										uni.showModal({
											content:'旧密码不正确',
											showCancel:false,
										})
									}else{
										uni.showModal({
											content:e.data.msg,
											showCancel:false,
										})
									}
									
									console.log(e)
								}
							})
						}
					}
				})
				
			}
		}
	}
</script>

<style lang="scss">
	.cardno{
		color: rgba(0, 0, 0, 0.4);
		font-size: 30rpx;
	}
</style>
